#include "delge_squirrelaudio_music.h"

void s_Audio_Music_RegisterFunctions (HSQUIRRELVM v)
{
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_Play,				_SC("Music_Play"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_Pause,				_SC("Music_Pause"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_Resume,				_SC("Music_Resume"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_SetPlaybackMode,		_SC("Music_SetPlaybackMode"),			_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_GetPlaybackMode,		_SC("Music_GetPlaybackMode"),			_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_SetVolume,			_SC("Music_SetVolume"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_GetVolume,			_SC("Music_GetVolume"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_GetPosition,			_SC("Music_GetPosition"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_GetLengthInMS,		_SC("Music_GetLengthMS"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_IsPlaying,			_SC("Music_IsPlaying"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Audio_Music_IsPaused,			_SC("Music_IsPaused"),					_SC("*"));
}

SQInteger s_Audio_Music_Play (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	pMusic->Play();

	return 0;
}

SQInteger s_Audio_Music_Pause (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	pMusic->Pause();

	return 0;
}

SQInteger s_Audio_Music_Resume (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	pMusic->Resume();

	return 0;
}

SQInteger s_Audio_Music_SetPlaybackMode (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;
	SQInteger				ePlaybackMode;

	sq_getstring			(v, 2, &sResourceName);
	sq_getinteger			(v, 3, &ePlaybackMode);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	pMusic->SetPlaybackMode((DelGEAudioPlaybackMode)ePlaybackMode);

	return 0;
}

SQInteger s_Audio_Music_GetPlaybackMode (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	sq_pushinteger			(v, (int)pMusic->GetPlaybackMode());

	return 1;
}

SQInteger s_Audio_Music_SetVolume (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;
	SQFloat					fVolume;

	sq_getstring			(v, 2, &sResourceName);
	sq_getfloat				(v, 3, &fVolume);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	pMusic->SetVolume(fVolume);

	return 0;
}

SQInteger s_Audio_Music_GetVolume (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	sq_pushfloat			(v, pMusic->GetVolume());

	return 1;
}

SQInteger s_Audio_Music_GetPosition (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	sq_pushfloat			(v, pMusic->GetPosition());

	return 1;
}

SQInteger s_Audio_Music_GetLengthInMS (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	sq_pushinteger			(v, pMusic->GetLengthInMS());

	return 1;
}

SQInteger s_Audio_Music_IsPlaying (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	sq_pushbool				(v, pMusic->IsPlaying());

	return 1;
}

SQInteger s_Audio_Music_IsPaused (HSQUIRRELVM v)
{
	const SQChar			*sResourceName;

	sq_getstring			(v, 2, &sResourceName);

	Music *pMusic = ResourceManager<Music>::GetResource(sResourceName);

	sq_pushbool				(v, pMusic->IsPaused());

	return 1;
}